# -*- python -*-
# Copyright (c) 2011 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.


Import('env')

test_is_broken_on_this_os=False
slop_args = []

if 'TRUSTED_ENV' in env and (env['TRUSTED_ENV'].Bit('windows') or
                             env['TRUSTED_ENV'].Bit('mac')):
  slop_args += ['-s', '10']
  # Number of milliseconds by which a thread is allowed to wake up
  # early, after invoking nanosleep (on Windows, implemnted via
  # Sleep()).  On WinXP, Sleep sometimes return early.

if 'TRUSTED_ENV' in env and env['TRUSTED_ENV'].Bit('windows'):
  test_is_broken_on_this_os=True

nexe = env.ComponentProgram('nanosleep_test',
                            'nanosleep_test.c',
                            EXTRA_LIBS=['${PTHREAD_LIBS}', '${NONIRT_LIBS}'])

# This is a timing test, so we only run on real hardware
is_on_vm = env.Bit('running_on_vm')

node = env.CommandSelLdrTestNacl(
    'nanosleep_test.out',
    nexe,
    args=slop_args)
env.AddNodeToTestSuite(node, ['small_tests'], 'run_nanosleep_test',
    is_broken=is_on_vm or test_is_broken_on_this_os)
